<?php
// 定义常见姓氏数组
$lastNames = [
    '赵', '钱', '孙', '李', '周', '吴', '郑', '王',
    '冯', '陈', '褚', '卫', '蒋', '沈', '韩', '杨'
];

// 定义不同风格的名字数组
$styles = [
    '古典文雅' => [
        '男' => ['逸轩', '俊辉', '浩然', '宇澄', '明哲', '睿渊'],
        '女' => ['诗涵', '雅琴', '雨薇', '婉清', '芷柔', '梦琪']
    ],
    '时尚现代' => [
        '男' => ['梓豪', '宇泽', '俊熙', '嘉豪', '铭轩', '子墨'],
        '女' => ['悦溪', '可昕', '雨桐', '思瑶', '紫萱', '语汐']
    ]
];

// 处理表单提交
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $gender = $_POST["gender"];
    $style = $_POST["style"];

    // 随机选择一个姓氏
    $lastName = $lastNames[array_rand($lastNames)];
    // 随机选择一个名字
    $firstName = $styles[$style][$gender][array_rand($styles[$style][$gender])];

    $generatedName = $lastName . $firstName;
}
?>

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>随机取名游戏</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <div class="container">
        <h1>随机取名游戏</h1>
        <?php if (isset($generatedName)): ?>
            <div class="result">
                <p>为您生成的名字是：<?php echo $generatedName; ?></p>
            </div>
        <?php endif; ?>
        <form method="post">
            <label for="gender">选择性别：</label>
            <select name="gender" id="gender">
                <option value="男">男</option>
                <option value="女">女</option>
            </select>
            <br>
            <label for="style">选择名字风格：</label>
            <select name="style" id="style">
                <?php foreach ($styles as $styleName => $names): ?>
                    <option value="<?php echo $styleName; ?>"><?php echo $styleName; ?></option>
                <?php endforeach; ?>
            </select>
            <br>
            <button type="submit">生成名字</button>
        </form>
    </div>
</body>

</html>